//
//  ViewController.m
//  用户登录软件界面
//
//  Created by ibokan on 14-10-29.
//  Copyright (c) 2014年 ibokan. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (strong, nonatomic) IBOutlet UITextField *dengluText;
@property (strong, nonatomic) IBOutlet UITextField *dengluPWText;
- (IBAction)resign:(UIButton *)sender;
- (IBAction)viewclick:(id)sender;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)resign:(UIButton *)sender {
    
    
//    NSString *username = [NSString new];
//    username = [username  stringByTrimmingCharactersInSet:[NSCharacterSet  whitespaceAndNewlineCharacterSet]];
    
    
    
    if (self.dengluText.text.length == 0 ) {
         UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"用户登录" message:@"对不起，请您输入账号！" delegate:self cancelButtonTitle:@"知道了！" otherButtonTitles:nil];
        [alert show];
        
    }else {
    
    NSUserDefaults *userdefaults = [NSUserDefaults standardUserDefaults];
    if ([userdefaults objectForKey:[NSString stringWithFormat:@"%@",self.dengluText.text]]==nil) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"用户登录" message:@"对不起，您输入的账号不存在！" delegate:self cancelButtonTitle:@"知道了！" otherButtonTitles:nil];
        [alert show];
        self.dengluText.text = nil;
        self.dengluPWText.text = nil;
    }else{
        if ([[userdefaults objectForKey:[NSString stringWithFormat:@"%@",self.dengluText.text]]isEqualToString:self.dengluPWText.text]) {
            UIViewController *denglu = [self.storyboard instantiateViewControllerWithIdentifier:@"denglu"];
            [self.navigationController pushViewController:denglu animated:YES];
        }else{
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"用户登录" message:@"对不起，您输入的账号与密码不符！" delegate:self cancelButtonTitle:@"知道了！" otherButtonTitles:nil];
            [alert show];
            self.dengluText.text = nil;
            self.dengluPWText.text = nil;
        }
    }
    }
    
}



- (IBAction)viewclick:(id)sender {
    [self.dengluPWText resignFirstResponder];
    [self.dengluText resignFirstResponder];
}
-(IBAction)textFieldDidEndEditing:(UITextField *)textField{
    [textField resignFirstResponder];
}



@end
